home *** CD-ROM | disk | FTP | other *** search
- /*
- * GMS FiReWoRkS (c) 1996 Richard Clark - PhiRatE
- *
- * Fireworks using GMS in E, Requires E 3.0+
- *
- * Code and execs freely distributable. If you use complete functions from
- * this code, please put my name somewhere in your docs. And send me email
- * about your software. This applies to commercial software as well :).
- *
- * Note: The timings etc were set up for an A1200 +fast, they could look
- * quite sad on anything slower, but on a fast machine, go ahead and
- * decrease the delay values in the process procedures!
- *
- * Recommended timing for 040+ ... Change all of 'em to 3 or lower! >:)
- */
-
- OPT PREPROCESS -> Allow our function defines
-
- MODULE 'games','games/games','games/sound'
- MODULE '*fireworksmod','*wordims'
-
- ENUM ERR_NONE,ERR_REFUSE,ERR_FATAL
-
- DEF screen:PTR TO gamescreen, explosive:PTR TO sound,sparks:PTR TO sound
-
- PROC init()
- IF (gmsbase:=OpenLibrary('GMS:GPI/Master.GPI',0))=NIL
- Throw(ERR_FATAL,'Cannot load GMS!!') -> Throw pointer to message
- ENDIF
-
- SetUserPrefs(NIL)
-
- screen := AddScreen([TAGS_GAMESCREEN,0,
- GSA_PALETTE,{pal},
- GSA_SCRWIDTH,320,
- GSA_SCRHEIGHT,256,
- GSA_AMTCOLOURS,32,
- GSA_RASTERLIST,[WAITLINE(180),
- MIRROR,
- NEWPALETTE(0,32,{waterpal}),
- RASTEND],
- TAGEND])
-
- AllocAudio()
- AllocBlitter() -> We use GMS blitter functions so we must alloc
- ENDPROC
-
- /* Deallocate stuff */
-
- PROC deinit()
- FreeBlitter()
- FreeAudio()
- IF screen THEN DeleteScreen(screen); screen := 0;
- IF gmsbase THEN CloseGMS(); gmsbase := 0;
- ENDPROC
-
- PROC main() HANDLE
- /*
- * Lets make big bangs and little bangs and colourful bangs and well, you
- * get the picture.
- */
-
- DEF fwork:PTR TO firework,fwlist=NIL:PTR TO firework,count=NIL,nxt,pc=NIL
- DEF temp=NIL
-
- explosive := [
- SMV1,0, -> Structure version.
- CHANNEL_ALL, -> Channel to play through.
- 1, -> Priority.
- 0, -> Header
- 0, -> Address.
- 0, -> Length.
- OCT_C3, -> Period.
- 100, -> Volume.
- 0, -> Attributes.
- {file_explosive} -> Sample file.
- ]:sound;
-
- sparks := [
- SMV1,0, -> Structure version.
- CHANNEL1, -> Channel to play through.
- 2, -> Priority.
- 0, -> Header
- 0, -> Address.
- 0, -> Length.
- OCT_C3, -> Period.
- 50, -> Volume.
- SREPEAT, -> Attributes.
- {file_sparks} -> Sample file.
- ]:sound;
-
- init()
- InitSound(explosive)
- InitSound(sparks)
-
- ShowScreen(screen) -> Display the GMS screen
-
- count:=100
-
- REPEAT
-
- INC count
- INC pc
-
- IF pc>4000 -> Loop at 100 seconds (1 minute 20secs)
- pc:=0
- count:=100
- ENDIF
-
- -> Complete routine list and timing
-
- IF pc>1090
- fwlist,count := fast_single(fwlist,count)
- ELSEIF pc>1060
- -> do nothing
- ELSEIF pc>1000
- fwlist,count,temp := char_word(fwlist,count,'BYE',temp)
- ELSEIF pc>600
- fwlist,count := fast_double(fwlist,count)
- ELSEIF pc>599
- count:=80 -> Make sure fast_dobe starts right up
- ELSEIF pc>170
- fwlist,count := thick_fountain(fwlist,count,pc)
- ELSEIF pc>100
- fwlist,count,temp := char_word(fwlist,count,'GMS',temp)
- ELSEIF pc>10
- -> do nothing
- ELSEIF pc>0
- fwlist,count := slow_huge(fwlist,count)
- ENDIF
-
- fwork:=fwlist
-
- WHILE fwork
- nxt:=fwork.next -> Get the next one for safety
-
- fwork.clear(screen,BUFFER1) -> Clear the firework from the screen
- fwlist:=fwork.update(fwlist) -> Update the firework
-
- IF (fwork.flags AND FW_KILLME) -> If firework is to be killed..
- END fwork -> Kill it :)
- ELSE
- fwork.draw(screen,BUFFER1) -> Draw the firework
- ENDIF
-
- fwork:=nxt -> Loop with next one!
- ENDWHILE
-
- WaitVBL()
-
- UNTIL (ReadMouse(JPORT1) AND MB_LMB)
-
- EXCEPT DO -> If there's an error or we're at the end, dealloc.
-
- FreeSound(sparks)
- FreeSound(explosive)
- deinit()
-
- -> Quick, easy, and friendly way of displaying an error
-
- IF exception
- EasyRequestArgs(0,[20,0,'Fireworks error:',exceptioninfo,'DAMN'],0,NIL)
- ELSE
- EasyRequestArgs(0,[100,50,'FiReWoRkS!!',
- 'This demo was written by PhiRatE using\nAmigaE v3.1 and GMS!!\n\nE-mail: phirate@sans.vuw.ac.nz',
- 'Woohoo!'],0,NIL)
- ENDIF
-
- ENDPROC
-
-
- /*-*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*-*-*/
- /* Firework process procedures for different displays */
- /*-*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*-*-*/
-
-
- /****************************************************************************
- ** Fast, single-explosion fireworks.
- */
-
- PROC fast_single(fwlist:PTR TO firework,count)
-
- DEF f:PTR TO firework,p,flags
-
- IF count>=10 -> CHANGE THIS NUMBER IF YOU GOT A FAST MACHINE!! :)
- count:=0
- p:=Shr(FastRandom(12),1)
- IF FastRandom(6)=1 THEN flags:=FW_MULTIHUE ELSE flags:=NIL
- flags:=flags OR FW_BIGSPARK -> Big spark
-
- NEW f.new(160,180, -> X and Y start
- FastRandom(5)-2,FastRandom(4)+3, -> X and Y velocities
- 4, -> Gravity delay
- (p*4)+8, -> Color value
- 0, -> Background color
- 25, -> Firework lifetime
- 1, -> Number of explosions
- flags) -> Flags
-
- IF fwlist=NIL THEN fwlist:=f ELSE fwlist.add(f) -> Put f into list
- ENDIF
- ENDPROC fwlist,count
-
- /****************************************************************************
- ** Fast, with the occasional double-explosion.
- */
-
- PROC fast_double(fwlist:PTR TO firework,count)
-
- DEF f:PTR TO firework,p,flags
-
- IF count>=60
- count:=0
- p:=Shr(FastRandom(12),1)
- IF FastRandom(6)=1 THEN flags:=FW_MULTIHUE ELSE flags:=NIL
- flags:=flags OR FW_BIGSPARK OR FW_EXSOUND -> Explosion-sparks get same flags
-
- NEW f.new(160,180, -> X and Y start
- FastRandom(5)-2,FastRandom(3)+4, -> X and Y velocities
- 4, -> Gravity delay
- (p*4)+8, -> Color value
- 0, -> Background color
- 25, -> Firework lifetime
- 2, -> Number of explosions
- flags) -> Flags
-
- IF fwlist=NIL THEN fwlist:=f ELSE fwlist.add(f) -> Put f into list
- ENDIF
- ENDPROC fwlist,count
-
- /****************************************************************************
- ** Slow but massive bangs :)
- */
-
- PROC slow_huge(fwlist:PTR TO firework,count)
-
- DEF f:PTR TO firework,p,flags
-
- IF count>=100
- count:=0
- p:=Shr(FastRandom(12),1)
- IF FastRandom(6)=1 THEN flags:=FW_MULTIHUE ELSE flags:=NIL
- flags:=flags OR FW_BIGSPARK OR FW_MASSIVE OR FW_EXSOUND -> Big spark
- NEW f.new(160,180, -> X and Y start
- FastRandom(5)-2,FastRandom(4)+3, -> X and Y velocities
- 4, -> Gravity delay
- (p*4)+8, -> Color value
- 0, -> Background color
- 25, -> Firework lifetime
- 1, -> Number of explosions
- flags) -> Flags
-
- IF fwlist=NIL THEN fwlist:=f ELSE fwlist.add(f) -> Put f into list
- ENDIF
- ENDPROC fwlist,count
-
- /****************************************************************************
- ** Explodes into the word, letter by letter.
- */
-
- PROC char_word(fwlist:PTR TO firework,count,word:PTR TO CHAR,c)
-
- DEF f:PTR TO firework,p,flags,xv
-
- IF count>=25
- count:=0
- IF c>=StrLen(word) THEN c:=0
- xv:=(2*(c-Shr(StrLen(word),1)))/Shr(StrLen(word),1)
- p:=Shr(FastRandom(12),1)
- IF FastRandom(6)=1 THEN flags:=FW_MULTIHUE ELSE flags:=NIL
- flags:=flags OR FW_BIGSPARK OR FW_IMAGE OR FW_KEEPFLAGS -> Big spark
-
- NEW f.new(160,180, -> X and Y start
- xv,FastRandom(3)+4, -> X and Y velocities
- 4, -> Gravity delay
- (p*4)+8, -> Color value
- 0, -> Background color
- 25, -> Firework lifetime
- 1, -> Number of explosions
- flags, -> Flags
- 2,2,getchar(word,c))-> Character display system
-
- IF fwlist=NIL THEN fwlist:=f ELSE fwlist.add(f) -> Put f into list
- INC c
- ENDIF
- ENDPROC fwlist,count,c
-
- /****************************************************************************
- ** Big funky fountain.
- */
-
- PROC thick_fountain(fwlist:PTR TO firework,count,pc)
-
- DEF f:PTR TO firework,p,flags
-
- IF (pc<200) THEN PlaySound(sparks)
-
- IF count>=2
- count:=0
- p:=Shr(FastRandom(12),1)
- IF FastRandom(6)=1 THEN flags:=FW_MULTIHUE ELSE flags:=NIL
- flags:=flags OR FW_BIGSPARK OR FW_SMALL OR FW_KEEPFLAGS -> Big spark
-
- NEW f.new(160,180, -> X and Y start
- FastRandom(3)-1,FastRandom(4)+2, -> X and Y velocities
- 4, -> Gravity delay
- (p*4)+8, -> Color value
- 0, -> Background color
- 10, -> Firework lifetime
- 1, -> Number of explosions
- flags) -> Flags
-
- IF fwlist=NIL THEN fwlist:=f ELSE fwlist.add(f) -> Put f into list
- ENDIF
- ENDPROC fwlist,count
-
- -> Standard palette, stored here simply because I needed to make sure
- -> that the water palette was similar. Converted to 12bit to make it ECS-OK
-
- pal:
- LONG $000000,$000000,$000010,$000010,$000030,$000050,$000060,$000070
- LONG $F0F000,$A06000,$803000,$400000,$F0F0F0,$A0A0A0,$707070,$404040
- LONG $F00000,$A00000,$700000,$400000,$00F000,$00A000,$007000,$004000
- LONG $A0A0F0,$8080A0,$606070,$202040,$F0F000,$A0A000,$707000,$404000
-
- waterpal:
- LONG $000010,$000020,$000020,$000040,$000050,$000060,$000070,$000080
- LONG $A0A060,$804040,$602020,$300010,$8080A0,$707080,$303040,$101020
- LONG $A00020,$800020,$500020,$300020,$00A020,$008020,$005020,$003020
- LONG $7070A0,$404080,$202050,$000020,$A0A020,$808020,$505020,$303020
-
- -> Water palette, same palette with a bit of blue and some dimming
-
- file_explosive:
- CHAR 'GMS:demos/data/SND.Explosive',0
- file_sparks:
- CHAR 'GMS:demos/data/SND.Sparks',0
-
-
-